package top.cwk.dubbo.web.controller.customer;

import top.cwk.dubbo.api.customer.ICustomerService;
import top.cwk.dubbo.entity.customer.Customer;

import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

/**
 * @ClassName CustomerThreadTask
 * @Description TODO
 * @Author 维康
 * @Date 2018/7/9 17:02
 * @Version 1.0
 **/
public class CustomerThreadTask implements Callable<Long> {

    private ICustomerService customerService;
    private CountDownLatch latch;
    private static final int count = 1000;
    private String threadName;

    public CustomerThreadTask(ICustomerService customerService , CountDownLatch latch , String threadName) {
        this.customerService = customerService;
        this.latch = latch;
        this.threadName = threadName;
    }

    @Override
    public Long call() {
        long start = System.currentTimeMillis();
        for (int i = 0 ; i<count ; i++){
            Customer customer = new Customer(threadName+"_"+i,"000000","中国*北京");
            customerService.saveCustomer(customer);
            //System.out.println(customer.toString());
        }
        long end = System.currentTimeMillis();
        latch.countDown();
        return end-start;
    }

}
